import React from 'react';
import { Form, InputNumber } from 'antd';
import { IMetaFormProps, MetadataFormContext } from '../interface';
import { useGetExtraInfo } from '../hooks';

function Index(props: IMetaFormProps) {
  const { id, require } = props;
  const formContext: any = React.useContext(MetadataFormContext) || {};
  const extraInfo = useGetExtraInfo(formContext.fields, id, formContext.form);
  return (
    <Form.Item label={extraInfo?.label || id} name={id} rules={[{ required: require }]} help={extraInfo?.help} tooltip={extraInfo?.tooltip}>
      <InputNumber placeholder={extraInfo?.placeholder} />
    </Form.Item>
  );
}

export default React.memo(Index);
